package com.jhs.kjs.handler;

import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMessage.RecipientType;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import com.jhs.kjs.dto.EmailDTO;
@Component
public class SendMailHandler {
	private static final Logger logger = LoggerFactory.getLogger(SendMailHandler.class);
	@Autowired
    protected JavaMailSender  mailSender;
	
	public void sendEmail(EmailDTO email){
        logger.debug("--------------------메일발송"+email.toString());
        try {
	        MimeMessage msg = mailSender.createMimeMessage();
	        msg.setSubject(email.getType());
	        
	        msg.setText(email.getContents());
	        msg.setRecipient(RecipientType.TO , new InternetAddress(email.getReceiver()));
	        msg.setFrom(new InternetAddress("phprate@nate.com"));
	        mailSender.send(msg);
        } catch(Exception e) {
        	e.printStackTrace();
        }
        logger.debug("--------------------메일발송 완료");
    }
}
